//
//  AdressListCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/30.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

protocol AdressListCellDelegate:NSObjectProtocol {
    
    func setupDefualAdressBtnDidTap(btn : UIButton,model : AddressInfoModel)
    func deleAdressBtnDidTap(model : AddressInfoModel)


}

class AdressListCell: BaseTableViewCell {
    
    weak var delegate : AdressListCellDelegate?
    
    
    @IBOutlet weak var nameLabel: UILabel!
    
    @IBOutlet weak var phoneLabel: UILabel!
    
    @IBOutlet weak var seletBtn: UIButton!
    @IBOutlet weak var adressLabel: UILabel!
    
    
    @IBOutlet weak var defualLabel: UILabel!
    
    var model : AddressInfoModel?{
        
        didSet{
            if model == nil {
                return
            }
            
            nameLabel.text = model?.true_name
            
            phoneLabel.text = model?.mob_phone
            
            adressLabel.text = model!.area_info + model!.address
            
            if model?.is_default == "1" {
                
                seletBtn.isSelected = true
                defualLabel.text = "默认地址"
            }else{
                
                seletBtn.isSelected = false
                
                defualLabel.text = "设为默认"

            }

        
        
        }
    
    
    }

    @IBAction func btnDidTap(_ sender: UIButton) {
        
        if model == nil {
            return
        }

        
       delegate?.setupDefualAdressBtnDidTap(btn: sender, model: model!)
    }
    
    @IBAction func deleBtnDidTap(_ sender: UIButton) {
        
        if model == nil {
            return
        }

        
        delegate?.deleAdressBtnDidTap(model: model!)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        seletBtn.imageEdgeInsets = UIEdgeInsetsMake(8, 8, 8, 8)
        contentView.backgroundColor = UIColor.white

        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
